package com.oscar.ehome.view.pageview.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.oscar.ehome.R;
import com.oscar.ehome.base.C;
import com.oscar.ehome.bean.messageBean.MessageListBean;
import com.oscar.ehome.bean.pagebean.XiaoXiXiangQingBean;
import com.oscar.ehome.provider.gildeimage.GildeUtils;
import com.oscar.ehome.utils.basethem.TintManager;
import com.oscar.ehome.utils.system.SystemConfigFactory;
import com.oscar.ehome.utils.util.DateUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/12/7
 */

public class XiaoXiTongJiAdapter extends BaseAdapter {

    private List<XiaoXiXiangQingBean.liebiaoshuju> list = new ArrayList<>();
    private LayoutInflater mInflater;
    private Context mContext = null;
    XiaoXiXiangQingBean.liebiaoshuju bean;


    public XiaoXiTongJiAdapter(Context context, List<XiaoXiXiangQingBean.liebiaoshuju> list) {
        this.mContext = context;
        this.list = list;
        mInflater = LayoutInflater.from(context);
    }

    public void setLists(List<XiaoXiXiangQingBean.liebiaoshuju> list) {
        this.list = list;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        XiaoXiTongJiAdapter.ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.message_tongjiitem, null);
            holder = new XiaoXiTongJiAdapter.ViewHolder();
            holder.message_zongrenshu = (TextView) convertView.findViewById(R.id.message_zongrenshu);
            holder.message_img = (ImageView) convertView.findViewById(R.id.message_img);
            holder.message_renshu = (TextView) convertView.findViewById(R.id.message_renshu);
            holder.message_title_text = (TextView) convertView.findViewById(R.id.message_title_text);
            holder.message_time_text = (TextView) convertView.findViewById(R.id.message_time_text);
            holder.message_title = (TextView) convertView.findViewById(R.id.message_title);

            convertView.setTag(holder);
        } else {
            holder = (XiaoXiTongJiAdapter.ViewHolder) convertView.getTag(); //
        }

        if (list.size() > 0) {
            bean = list.get(position);
            if (bean != null) {
                holder.message_zongrenshu.setText("/"+bean.getAllCanReadNum());
                holder.message_renshu.setText(bean.getReadNum());
                holder.message_title.setText(bean.getTitle());
                String date = DateUtil.timeLogic(bean.getUpdateDate());
                holder.message_time_text.setText(date);
                if (bean.getType() != null && !bean.getType().equals("")) {
                    String type = bean.getType();
                    switch (type) {
                        case "1"://通知
                            holder.message_img.setImageResource(R.mipmap.tongzhi1);
                            holder.message_title_text.setText(R.string.message_inform);
                            break;
                        case "2"://激励
                            holder.message_img.setImageResource(R.mipmap.jili1);
                            holder.message_title_text.setText(R.string.message_exciting);
                            break;
                        case "3"://产品
                            holder.message_img.setImageResource(R.mipmap.chanpin1);
                            holder.message_title_text.setText(R.string.message_product);
                            break;
                        case "4"://会议
                            holder.message_img.setImageResource(R.mipmap.huiyi1);
                            holder.message_title_text.setText(R.string.message_meeting);
                            break;
                        case "5"://系统
                            holder.message_img.setImageResource(R.mipmap.xitong1);
                            holder.message_title_text.setText(R.string.message_system);
                            break;
                    }
                }


            }
        }


        return convertView;
    }

    class ViewHolder {
        TextView message_renshu;//
        TextView message_zongrenshu;//
        TextView message_title_text;//
        TextView message_time_text;
        TextView message_title;
        ImageView message_img;
    }

}
